package com.lxl.hadoop.etl;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @Author lixilin
 * @Date 2022/1/8 17:40
 * @Description
 */
public class LogDriver {
    public static void main(String[] args) throws Exception{
        args = new String[]{"D:\\bigdata\\input-tmp-data\\etl", "D:\\bigdata\\input-tmp-data\\etl\\output"};
        Configuration conf = new Configuration();
        // 获取job对象
        Job job = Job.getInstance(conf);
        // 设置jar存储的位置
        job.setJarByClass(LogDriver.class);
        // 关联map类
        job.setMapperClass(LogMapper.class);
        // 设置最终的数据输出key和value的类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        // 不需要ReduceTask
        job.setNumReduceTasks(0);

        // 设置输入路径和输出路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        // 提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
